﻿using DLog.Model;
using DLog.Tools;
using DLog.IStorageDal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DLog.NotepadDal
{
    public class AccessDal : IDal
    {
        private string path;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="connectionString"></param>
        public AccessDal(string connectionString)
        {
            path = RuleConnectioinstring(connectionString);
        }
        /// <summary>
        /// 规则配置路径
        /// </summary>
        /// <param name="pathStr"></param>
        /// <returns></returns>
        public string RuleConnectioinstring(string pathStr)
        {
            if (pathStr.Contains("[Hour]"))
            {
                pathStr = pathStr.Replace("[Hour]", DateTime.Now.ToString("yyyy-MM-dd-hh"));
            }
            else if (pathStr.Contains("[Date]"))
            {
                pathStr = pathStr.Replace("[Date]", DateTime.Now.ToString("yyyy-MM-dd"));
            }
            else if (pathStr.Contains("[Month]"))
            {
                pathStr = pathStr.Replace("[Month]", DateTime.Now.ToString("yyyy-MM"));
            }
            return pathStr;
        }
        /// <summary>
        /// 通过日志编号查询日志模型信息
        /// </summary>
        /// <param name="LogId"></param>
        /// <returns></returns>
        public LogModel SelectModel(int logId)
        {
            return new LogModel();
        }
        /// <summary>
        /// 通过日志等级获得所以属于这个等级的日志数据集，返回个数
        /// </summary>
        /// <param name="logLevel"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public List<LogModel> SelectList(int logLevel)
        {
            return new List<LogModel>();
        }
        /// <summary>
        /// 通过日志等级获得所以属于这个等级的某一页的日志数据集，返回个数
        /// </summary>
        /// <param name="logLevel"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public List<LogModel> SelectList(int logLevel, int pageIndex, int pageSize)
        {
            return new List<LogModel>();
        }
        /// <summary>
        /// 通过创建的时间区间获得所以属于这个等级的某一页的日志数据集，返回个数
        /// </summary>
        /// <param name="createStartDate"></param>
        /// <param name="createEndDate"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public List<LogModel> SelectList(DateTime createStartDate, DateTime createEndDate, int pageIndex, int pageSize)
        {
            return new List<LogModel>();
        }
        /// <summary>
        /// 通过创建的日志等级和时间区间获得所以属于这个等级的某一页的日志数据集，返回个数
        /// </summary>
        /// <param name="logLevel"></param>
        /// <param name="createStartDate"></param>
        /// <param name="createEndDate"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public List<LogModel> SelectList(int logLevel, DateTime createStartDate, DateTime createEndDate, int pageIndex, int pageSize)
        {
            return new List<LogModel>();
        }
        /// <summary>
        /// 更新日志信息
        /// </summary>
        /// <param name="lm"></param>
        /// <returns></returns>
        public int Update(LogModel lm)
        {
            return 1;
        }
        /// <summary>
        /// 插入日志信息
        /// </summary>
        /// <param name="lm"></param>
        /// <returns></returns>
        public int Insert(LogModel lm)
        {
            Dictionary<string, string> logDic = new Dictionary<string, string>();
            logDic.Add("记录时间", lm.CreateDate.ToString());
            logDic.Add("日志等级", lm.LogLevel.ToString());
            logDic.Add("来源", lm.Origin);
            logDic.Add("信息", lm.Message);
            logDic.Add("日志堆栈", lm.StackTrade);
            logDic.Add("/********************************", "********************************/");
            NotepadHelper.LogWrite(logDic, path);
            return 1;
        }
        /// <summary>
        /// 通过日志编号删除日志
        /// </summary>
        /// <param name="logId"></param>
        /// <returns></returns>
        public int Delete(int logId)
        {
            return 1;
        }
        /// <summary>
        /// 删除日志信息
        /// </summary>
        /// <param name="lm"></param>
        /// <returns></returns>
        public int Delete(LogModel lm)
        {
            return 1;
        }
    }
}
